#include "thread-factory.h"

// #define DEBUG_PROGRAM

struct ThreadFactory {
};

ThreadFactory *createThreadFactory() {
    ThreadFactory *factory = (ThreadFactory *) malloc(sizeof(ThreadFactory));

    if (factory == NULL) {
# ifdef DEBUG_PROGRAM
        printf("Thread Factory Apply Form Memory Fail!\n");
# endif
        return NULL;
    }

# ifdef DEBUG_PROGRAM
    printf("Thread Factory Create Success!\n");
# endif
    return factory;
}

void destroyThreadFactory(ThreadFactory *factory) {
    free(factory);

# ifdef DEBUG_PROGRAM
    printf("Thread Factory Destroy Success!\n");
# endif
}

ThreadInfo *createThread(ThreadFactory *factory, callback task_function, void *args) {
    ThreadInfo *info = (ThreadInfo *) malloc(sizeof(ThreadInfo));

    if (info == NULL) {
# ifdef DEBUG_PROGRAM
        printf("Thread Info Apply Form Memory Fail!\n");
# endif
        return NULL;
    }

    pthread_create(&info->pid, NULL, task_function, args);
    info->alive_time = time(NULL);

# ifdef DEBUG_PROGRAM
    // printf("Thread Create Success!\n");
# endif
    return info;
}
